
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/index/index_router.dart';
import 'package:flutter_deer/index/models/user_betting_entity.dart';
import 'package:flutter_deer/res/gaps.dart';
import 'package:flutter_deer/routers/fluro_navigator.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/util/theme_utils.dart';
import 'package:flutter_deer/res/dimens.dart';
import 'package:flutter_deer/widgets/fadein_text.dart';
import 'package:flutter_deer/widgets/my_card.dart';
import 'package:flutter_deer/widgets/my_refresh_list.dart';
import 'package:flutter_deer/widgets/state_layout.dart';
import 'package:flutter_gen/gen_l10n/deer_localizations.dart';
import 'package:intl/intl.dart';
import 'package:lottie/lottie.dart';
import 'package:text_scroll/text_scroll.dart';

class IndentSearchListPage extends StatefulWidget {

  const IndentSearchListPage({
    super.key,
    required this.list
  });

  final List<UserBettingEntity> list;

  @override
  _IndentSearchListPageState createState() => _IndentSearchListPageState();
}

class _IndentSearchListPageState extends State<IndentSearchListPage> with AutomaticKeepAliveClientMixin<IndentSearchListPage>, SingleTickerProviderStateMixin {

  @override
  bool get wantKeepAlive => false;

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  Future<dynamic> _onRefresh() async {
  }

  Future<dynamic> _loadMore() async {
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    final TextStyle? textTextStyle = Theme
        .of(context)
        .textTheme
        .bodyMedium
        ?.copyWith(fontSize: Dimens.font_sp12);
    final bool isDark = context.isDark;
    if(widget.list.length==0){
      return Container(
        width: MediaQuery.of(context).size.width,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Lottie.asset('assets/lottie/football_game_order.json',width: MediaQuery.of(context).size.width/3,fit: BoxFit.cover),
              Gaps.vGap16,
              FadeInText(text: '${DeerLocalizations.of(context)!.noOrderInformation.nullSafe}')
            ],
          ),
        ),
      );
    }
    return DeerListView(
        itemCount: widget.list!.length!,
        stateType: StateType.order!,
        onRefresh: _onRefresh,
        loadMore: _loadMore,
        hasMore: false,
        itemBuilder: (_, index) {
          final UserBettingEntity? item = widget.list!.elementAt(index);
          Text remarkText = Text('');
          if(item?.status=='1'){
            remarkText = Text('+'+NumberFormat.decimalPattern('en_us').format(item!.winScore).toString(),style: TextStyle(color: Colors.red),);
          }else if(item?.status=='2'){
            remarkText = Text('-'+NumberFormat.decimalPattern('en_us').format(item!.score).toString(),style: TextStyle(color:Colors.green),);
          }
          return GestureDetector(
            onTap: (){
              NavigatorUtils.push(context, IndexRouter.bettingDetailPage,arguments: item.id.toString());
            },
            child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10.0,vertical: 5),
                child: MyCard(
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 5),
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            SizedBox(height: 5,),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text('${DeerLocalizations.of(context)!.playWays.nullSafe}:'+(item!.playWay=='1'?"${DeerLocalizations.of(context)!.gamePositiveWave.nullSafe}":'${DeerLocalizations.of(context)!.gameAntiWave.nullSafe}')),
                                Text('${DeerLocalizations.of(context)!.orderTime.nullSafe}:${item.createOrderTime}')
                              ],
                            ),
                            SizedBox(height: 10,),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Expanded(child: Row(
                                  children: [
                                    Text('${DeerLocalizations.of(context)!.name.nullSafe}:'),
                                    Container(width: MediaQuery.of(context).size.width/2,child: TextScroll(item!.name.nullSafe,mode: TextScrollMode.endless,pauseBetween: Duration(milliseconds: 500),),)
                                  ],
                                )),
                                Gaps.hGap8,
                                remarkText
                              ],
                            ),
                            SizedBox(height: 10,),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Visibility(visible: item.bettingType=='1',child: Text('${DeerLocalizations.of(context)!.type.nullSafe}:${DeerLocalizations.of(context)!.score.nullSafe}')),
                                Visibility(visible: item.bettingType=='2',child: Text('${DeerLocalizations.of(context)!.type.nullSafe}:${DeerLocalizations.of(context)!.winOrLose.nullSafe}')),
                                Visibility(visible: item.bettingType=='3',child: Text('${DeerLocalizations.of(context)!.type.nullSafe}:${DeerLocalizations.of(context)!.numberOfGoalsScored.nullSafe}')),
                                Expanded(child: Text('')),
                                Text('${DeerLocalizations.of(context)!.bettingAmount.nullSafe}:'+NumberFormat.decimalPattern('en_us').format(item!.score).toString())
                              ],
                            ),
                            SizedBox(height: 5,),
                          ]
                      ),
                    )
                )
            ),
          );
        }
    );
  }
}